#ifndef SC_SERVER_H_INCLUDED
#define SC_SERVER_H_INCLUDED

#include "entity.h"
#include "player.h"
#include "car.h"
#include "map_mesh.h"
#include "race.h"
#include "sc_messageinfo.h"
#include "src/physics/be_physics_system.h"

// FIXME make generic message, add type to cm
// like m_joinedPlayers m_disapprovedPlayers m_approvedPlayers

// class ScServerCarMotionMessage
// {
// 	public:
// 		ScServerCarMotionMessage( Direction direction, Switch toggle ) : m_direction(direction), m_toggle(toggle) {};
// 		const Direction& getDirection() { return m_direction; }
// 		const Switch& getSwitch() { return m_toggle; }
// 
// 	private:
// 		Direction m_direction;
// 		Switch m_toggle;
// };

class ScServer
{
	public:
		ScServer();
		virtual ~ScServer();

		void		process( float timeDelta );

		void		addLocalPlayer()
		{
			boost::shared_ptr<Player> newplayer(new Player( m_idcounter++ ));
			m_players.push_back(newplayer);
		}

		void		addRemotePlayer( boost::shared_ptr<nClient> networkclient )
		{
			boost::shared_ptr<Player> newplayer(new Player( m_idcounter++ ));
			newplayer->setNetworkInfo( networkclient );
			m_players.push_back(newplayer);
		}

		void		newMessageAllClients(const string& msg);

		// PHYSICS
		BePhysicsSystem m_physicsSystem;
		boost::shared_ptr<btDynamicsWorld> m_dynamicsWorld;

		boost::shared_ptr<Map>	m_map;

		std::vector<boost::shared_ptr<Entity> >		m_entities;
		std::vector<boost::shared_ptr<Player> >		m_players;

// 		vector<string>	m_messages_in;
		vector<string>	m_messages_out;
		
		vector<string> logbufferQueue;
		void newLogMessage(const string& msg);

	private:

		void		parseIncomingMessages();
		void		processrace();

		boost::scoped_ptr<Race>		m_race;
		bool				m_startRace;
		long long			m_idcounter;



		// utils
			Settings*		settings;
			BeParser		parseH;
	
};

#endif
